﻿using System;
using System.Collections.Generic;
using System.Configuration;
using EvincePayroll.Data;
using EvincePayroll.Utility;
using Microsoft.Http;
using System.Runtime.Serialization;
using System.IO;

namespace EvinceUI
{
    public class EvincePayrollService : IDisposable
    {
        string _serviceURL = string.Empty;

        #region Service
        /// <summary>
        /// Ashcliff service that return service type like documents,project and users.
        /// </summary>
        /// <param name="serviceType"></param>
        public EvincePayrollService(ServiceTypes serviceType)
        {
            try
            {
                switch (serviceType)
                {

                    case ServiceTypes.Employee:
                        _serviceURL = ConfigurationManager.AppSettings["WCFServiceURL"] + "Employees/";
                        break;
                    case ServiceTypes.Account:
                        _serviceURL = ConfigurationManager.AppSettings["WCFServiceURL"] + "Accounts/";
                        break;
                    case ServiceTypes.Attendance:
                        _serviceURL = ConfigurationManager.AppSettings["WCFServiceURL"] + "Attendances/";
                        break;
                    case ServiceTypes.Home:
                        _serviceURL = ConfigurationManager.AppSettings["WCFServiceURL"] + "Homes/";
                        break;
                    case ServiceTypes.LeaveRequest:
                        _serviceURL = ConfigurationManager.AppSettings["WCFServiceURL"] + "LeaveRequests/";
                        break;
                    case ServiceTypes.NewsAndEvent:
                        _serviceURL = ConfigurationManager.AppSettings["WCFServiceURL"] + "NewsAndEvents/";
                        break;
                    case ServiceTypes.PageTemplate:
                        _serviceURL = ConfigurationManager.AppSettings["WCFServiceURL"] + "PageTemplates/";
                        break;
                    case ServiceTypes.UserRole:
                        _serviceURL = ConfigurationManager.AppSettings["WCFServiceURL"] + "UserRoles/";
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        #endregion


        //#region User

        ///// <summary>
        ///// Method to returns list of users registered on AshCliff's applicatin
        ///// </summary>
        ///// <returns></returns>
        ///// 
        public EmployeeData GetUser(string emailId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetEmployeeData/" + emailId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<EmployeeData>();
                        else
                            return null;
                    }
                }
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }
        
        public bool AuthenticateEmail(string emailId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    using (HttpResponseMessage response = client.Get(_serviceURL + "AuthenticateEmail/" + emailId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.AuthenticateEmail(emailId);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        //public List<ParentChildData> GetParentChild()
        //{
        //    try
        //    {

        //        using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
        //        {
        //            return client.GetParentChild().ToList<ParentChildData>();
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        LogEngine.Log(ex.Message);
        //        throw;
        //    }
        //}
        public PageTemplateData GetPageTemplate(string pageId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetPageTemplate/" + pageId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<PageTemplateData>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetPageTemplate(pageId);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }
        public List<PageTemplateData> GetPageTemplateList()
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetPageTemplateList/"))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<PageTemplateData>>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetPageTemplateList().ToList<PageTemplateData>();
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }


        public bool AuthenticateLogin(string emailId, string password)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    using (HttpResponseMessage response = client.Get(_serviceURL + "AuthenticateLogin/" + emailId + "," + password))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.AuthenticateLogin(emailId, password);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public bool Logout(string emailId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    using (HttpResponseMessage response = client.Get(_serviceURL + "Logout/" + emailId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.Logout(emailId, password);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public bool CheckExistingUser(string emailId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    using (HttpResponseMessage response = client.Get(_serviceURL + "CheckExistingUser/" + emailId ))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.CheckExistingUser(emailId);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }
        public List<EmployeeData> RegisterEmployee(EmployeeData employeeData, string emailId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    HttpContent content = HttpContentExtensions.CreateDataContract(employeeData);
                    using (HttpResponseMessage response = client.Post(_serviceURL + "RegisterEmployee/" + emailId,content))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<EmployeeData>>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.RegisterEmployee(employeeData, emailId).ToList();
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public List<EmployeeData> GetEmployeeList(string emailId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetEmployeeList/" + emailId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<EmployeeData>>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetEmployeeList(emailId).ToList();
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public List<AppOptionData> GetAppOption(string emailId, string key)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(employeeData);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetAppOption/" + emailId+","+key))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<AppOptionData>>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetAppOption(emailId, key).ToList<AppOptionData>();
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }


        public List<EmployeeData> GetEmployeeListForActivation(string emailId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(employeeData);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetEmployeeListForActivation/" + emailId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<EmployeeData>>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetEmployeeListForActivation(emailId).ToList();
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public List<EmployeeData> GetLeaveRequestsEmployeeData(string emailId, string userRole)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(employeeData);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetLeaveRequestsEmployeeData/" + emailId+","+userRole))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<EmployeeData>>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetLeaveRequestsEmployeeData(emailId, userRole).ToList();
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }


        public List<EmployeeLeaveRequestData> LeaveRequestsEmployee(EmployeeLeaveRequestData employeeRequestData, string emailId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    HttpContent content = HttpContentExtensions.CreateDataContract(employeeRequestData);
                    using (HttpResponseMessage response = client.Post(_serviceURL + "LeaveRequestsEmployee/" + emailId ,content ))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<EmployeeLeaveRequestData>>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.LeaveRequestsEmployee(employeeRequestData, emailId).ToList();
                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;

            }

        }


        public List<EmployeeLeaveRequestData> LeaveRequestsAdmin(string emailId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(employeeRequestData);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "LeaveRequestsAdmin/" + emailId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<EmployeeLeaveRequestData>>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.LeaveRequestsAdmin(emailId).ToList();
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }
        public bool UpdateLeaveRequestStatus(string emailId, string leaveRequestId, string status, string message, string numberOfDays, DateTime fromDate, string flag)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    HttpContent content = HttpContentExtensions.CreateDataContract(fromDate);
                    using (HttpResponseMessage response = client.Post(_serviceURL + "UpdateLeaveRequestStatus/" + emailId+","+leaveRequestId+","+status+","+message+","+numberOfDays+","+flag,content))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.UpdateLeaveRequestStatus(emailId, leaveRequestId, status, message, numberOfDays, fromDate, flag);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public List<EmployeeLeaveRequestData> GetRequestEmployee(string emailId, string status)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(employeeRequestData);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetRequestEmployee/" + emailId+","+status))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<EmployeeLeaveRequestData>>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetRequestEmployee(emailId, status).ToList();
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public List<AttendanceData> GetAttendanceAdmin(string emailId, DateTime fromDate, DateTime toDate)
        {
            try
            {
                
                using (HttpClient client = new HttpClient())
                {
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetAttendanceAdmin/" + emailId + "," + fromDate.ToString("MM-dd-yyyy") + "," + toDate.ToString("MM-dd-yyyy")))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<AttendanceData>>();
                        else
                            return null;
                    }
                }

                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetAttendanceAdmin(emailId, fromDate, toDate).ToList<AttendanceData>();
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public bool AddData(EmployeeLeaveRequestData employeeLeaveRequest, string emailId)
        {
            try
            {

                using (HttpClient client = new HttpClient())
                {
                    HttpContent content = HttpContentExtensions.CreateDataContract(employeeLeaveRequest);
                    using (HttpResponseMessage response = client.Post(_serviceURL + "AddData/" + emailId ,content))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }

                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.AddData(employeeLeaveRequest, emailId);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public bool UpdateData(EmployeeLeaveRequestData employeeLeaveRequest, Guid Id, string emailId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    HttpContent content = HttpContentExtensions.CreateDataContract(employeeLeaveRequest);
                    using (HttpResponseMessage response = client.Post(_serviceURL + "UpdateData/" + Id.ToString()+","+emailId, content))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }


                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.UpdateData(employeeLeaveRequest, Id, emailId);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public List<AppOptionData> getStatus(string emailId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                   // HttpContent content = HttpContentExtensions.CreateDataContract(employeeLeaveRequest);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "getSatus/" + emailId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<AppOptionData>>();
                        else
                            return null;
                    }
                }


                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.getSatus(emailId).ToList<AppOptionData>();
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public string DeleteData(int id, string emailId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    // HttpContent content = HttpContentExtensions.CreateDataContract(employeeLeaveRequest);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "DeleteData/"+id+"," + emailId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<string>();
                        else
                            return null;
                    }
                }

                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.DeleteData(id, emailId);


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }

        }

        public bool MarkAubsent()
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    // HttpContent content = HttpContentExtensions.CreateDataContract(employeeLeaveRequest);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "MarkAubsent/"))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.MarkAubsent();


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }
        public bool CheckOut(string emailId,string reason)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    // HttpContent content = HttpContentExtensions.CreateDataContract(employeeLeaveRequest);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "CheckOut/"+emailId+","+reason))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.CheckOut(emailId,reason);


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }
        public bool CheckIn(string emailId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    // HttpContent content = HttpContentExtensions.CreateDataContract(employeeLeaveRequest);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "CheckIn/" + emailId ))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.CheckIn(emailId);


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public bool updateEmployee(Guid id, int active, Guid role, string email)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    // HttpContent content = HttpContentExtensions.CreateDataContract(employeeLeaveRequest);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "updateEmployee/" + id + "," + active + "," + role + "," + email))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.updateEmployee(id, active, role, email);


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }





        }


        public List<UserRoleData> GetUserRoleList(string email)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    // HttpContent content = HttpContentExtensions.CreateDataContract(employeeLeaveRequest);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetUserRoleList/" + email))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<UserRoleData>>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetUserRoleList(email).ToList<UserRoleData>();
                //}



            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }



        }
        public bool GetUpdatedUserProfile(EmployeeData emdata, string email)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    HttpContent content = HttpContentExtensions.CreateDataContract(emdata);
                    using (HttpResponseMessage response = client.Post(_serviceURL + "GetUpdatedUserProfile/" + email,content))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetUpdatedUserProfile(emdata, email);
                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }



        public bool GetUpdatePassword(EmployeeData empdata, string email)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    HttpContent content = HttpContentExtensions.CreateDataContract(empdata);
                    using (HttpResponseMessage response = client.Post(_serviceURL + "GetUpdatePassword/" + email, content))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetUpdatePassword(empdata, email);


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }



        }

        public List<ExperienceData> GetExperinceByUserId(string emailId,string employeeId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(empdata);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetExperinceByUserId/" + emailId+","+employeeId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<ExperienceData>>();
                        else
                            return null;
                    }
                }
                //using(ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetExperinceByUserId(emailId, employeeId).ToList<ExperienceData>();
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }

        
        
        }


        public List<ExperienceData> GetUserExperince(string email)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(empdata);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetUserExperince/" + email))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<ExperienceData>>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetUserExperince(email).ToList<ExperienceData>();


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }



        }

        public bool AddYourExperince(ExperienceData experinceData, string email, string flag, string experinceId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    HttpContent content = HttpContentExtensions.CreateDataContract(experinceData);
                    using (HttpResponseMessage response = client.Post(_serviceURL + "AddYourExperince/" + email +","+flag+","+experinceId,content))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.AddYourExperince(experinceData, email, flag, experinceId);


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }



        }


        public bool DeleteExperience(string experienceId, string email)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(experinceData);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "DeleteExperience/" + experienceId + "," + email))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }

                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.DeleteExperience(experienceId, email);


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }



        }

        public ExperienceData EditExperience(string experienceId, string email)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(experinceData);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "EditExperience/" + experienceId + "," + email))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<ExperienceData>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.EditExperience(experienceId, email);


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }



        }


        public bool AddPage(PageTemplateData page, string email, string PageID)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    HttpContent content = HttpContentExtensions.CreateDataContract(page);
                    using (HttpResponseMessage response = client.Post(_serviceURL + "AddPage/" + email + "," +PageID,content))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.AddPage(page, email,PageID);


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }



        }

        public List<PageTemplateData> GetAllPageList()
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(page);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetAllPageList/"))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<PageTemplateData>>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetAllPageList().ToList<PageTemplateData>();
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public bool DeleteCMS(string pageId)
        {


            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(page);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "DeleteCMS/"+pageId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.DeleteCMS(pageId);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        
        
        }
        public bool AddGalleryPage(GalleryData gallery,string emailId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    HttpContent content = HttpContentExtensions.CreateDataContract(gallery);
                    using (HttpResponseMessage response = client.Post(_serviceURL + "AddGalleryPage/" + emailId,content))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.AddGalleryPage(gallery, emailId);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }
        public bool DeleteGalleryImage(string imageId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(gallery);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "DeleteGalleryImage/" + imageId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.DeleteGalleryImage(imageId);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }
        public bool UpdateGalleryImage(string imageId, string status)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(gallery);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "UpdateGalleryImage/" + imageId+","+status))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.UpdateGalleryImage(imageId,status);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public List<GalleryData> GetGallary(string emailId,bool flag)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(gallery);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetGallary/" + emailId + "," + flag))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<GalleryData>>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetGallary(emailId,flag).ToList<GalleryData>();
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }


        public List<AttendanceLogData> ShowAttendanceDetail(string email, string attendanceId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(gallery);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "ShowAttendanceDetail/" + email + "," + attendanceId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<AttendanceLogData>>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.ShowAttendanceDetail(email,attendanceId).ToList<AttendanceLogData>();


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }



        }
        public bool CreateRole(string email, string RoleName)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(gallery);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "CreateRole/" + email + "," + RoleName))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.CreateRole(email, RoleName);


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }



        }

        public List<UserRoleData> GetAllUserRole(string emailId)
        {

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(gallery);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetAllUserRole/" + emailId ))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<UserRoleData>>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetAllUserRole(emailId).ToList<UserRoleData>();


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        
        
        }


        public bool DeleteRole(string userId)
        {

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(gallery);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "DeleteRole/" + userId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.DeleteRole(userId);


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }


        }

        public List<EmployeeData> GetOnlineUsers(string emailId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(gallery);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetOnlineUsers/" + emailId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<EmployeeData>>();
                        else
                            return null;
                    }
                }

                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetOnlineUsers(emailId).ToList<EmployeeData>();


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }



        }

        public List<MenuTableData> GetMenuList(string emailId,string roleId)
        {

            try
            {
                if (roleId == string.Empty)
                    roleId = Constants.NA;
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(gallery);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetMenuList/" + emailId+","+roleId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<MenuTableData>>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetMenuList(emailId,roleId).ToList<MenuTableData>();


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        
        }
        public bool UpdateRoleAccess(string menuId, string roleId, string sortOrder, string parentId)
        {

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(gallery);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "UpdateRoleAccess/" + menuId + "," + roleId+ "," +sortOrder+ "," +parentId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.UpdateRoleAccess(menuId, roleId,sortOrder,parentId);


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }

        }

        public bool DeleteRoleAccess(string menuId, string roleId)
        {

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(gallery);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "DeleteRoleAccess/" + menuId + "," + roleId ))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }

                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.DeleteRoleAccess(menuId, roleId);


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }

        }

        public bool CreateMenuList(MenuTableData menuTableData , string email)
        {

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    HttpContent content = HttpContentExtensions.CreateDataContract(menuTableData);
                    using (HttpResponseMessage response = client.Post(_serviceURL + "CreateMenuList/" + email,content))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.CreateMenuList(menuTableData, email);


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }

        }

        public bool DeleteMenu(string menuId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(menuTableData);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "DeleteMenu/" + menuId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.DeleteMenu(menuId);


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        
        
        
        }

        public List<DynamicMenu> DynamicMenu(EmployeeData emoloyeeData)
        {

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    HttpContent content = HttpContentExtensions.CreateDataContract(emoloyeeData);
                    using (HttpResponseMessage response = client.Post(_serviceURL + "DynamicMenu/", content))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<List<DynamicMenu>>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.DynamicMenu(emoloyeeData).ToList<DynamicMenu>();


                //}

            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }

        }


        public LeaveMasterData GetLeaveMasterData(string emailId,string roleId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(emoloyeeData);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetLeaveMasterData/"+emailId+","+roleId))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<LeaveMasterData>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetLeaveMasterData(emailId,roleId);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public LeaveMasterData GetEmoloyeeLeaveMasterData(EmployeeData employee)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    HttpContent content = HttpContentExtensions.CreateDataContract(employee);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "GetLeaveMasterData/"+employee.Email+","+employee.UserRoleId.ToString()))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<LeaveMasterData>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.GetEmoloyeeLeaveMasterData(employee);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public LeaveMasterData CreateLeaveMaster(LeaveMasterData leaveMaster,string emailId)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    HttpContent content = HttpContentExtensions.CreateDataContract(leaveMaster);
                    using (HttpResponseMessage response = client.Post(_serviceURL + "CreateLeaveMaster/"+emailId, content))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<LeaveMasterData>();
                        else
                            return null;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.CreateLeaveMaster(leaveMaster,emailId);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public bool CalculateLeaveOfEmployee(EmployeeLeaveRequestData employeeLeaveRequestData, string email)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    HttpContent content = HttpContentExtensions.CreateDataContract(employeeLeaveRequestData);
                    using (HttpResponseMessage response = client.Post(_serviceURL + "CalculateLeaveOfEmployee/" + email, content))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.CalculateLeaveOfEmployee(employeeLeaveRequestData, email);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        
        
        
        
        }

        public bool CheckLeave(string leaveType,string email)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(employeeLeaveRequestData);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "CheckLeave/" + leaveType+","+email))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.CheckLeave(leaveType,email);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }


        }

        public bool LeaveWithdraw(string emailId, string leaveRequestId,bool flag)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //HttpContent content = HttpContentExtensions.CreateDataContract(employeeLeaveRequestData);
                    using (HttpResponseMessage response = client.Get(_serviceURL + "LeaveWithdraw/" + emailId + "," + leaveRequestId+","+flag))
                    {
                        response.EnsureStatusIsSuccessful();
                        if (response.Content.GetLength() > 0)
                            return response.Content.ReadAsDataContract<bool>();
                        else
                            return false;
                    }
                }
                //using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
                //{
                //    return client.LeaveWithdraw(emailId, leaveRequestId,flag);
                //}
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        public void Dispose()
        {
        }




    }
}